﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using ITOMMS.Entity;
using ITOMMS.Business;
using Watson.Core.Tools;

namespace ITOMMS.Web.UserManage
{
    public partial class UserAssetAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();

                //编辑
                if (Request.QueryString["id"] != null)
                {
                    string strId = Request.QueryString["id"].ToString();
                    int id = 0;
                    if (int.TryParse(strId, out id))
                    {
                        DataShow(id);
                    }
                }
            }
        }


        private void DataShow(int id)
        {
            tbCustEmpSoftListEntity entity = new tbCustEmpSoftListEntity();
            entity = new tbCustEmpSoftListEntity().GetById(id);
            ViewState["Entity"] = entity;

            ddlCompanyID.SelectedValue = entity.所属公司.ToString();


            if (ddlCompanyID.SelectedValue != "-1")
            {
                DropDownListHelper.InitDropList<tbCustEmployeeInfoEntity>(new tbCustEmployeeInfoEntity().GetAllByQuery("CompanyID=" + ddlCompanyID.SelectedValue), ddlEmployee, "ID", "RealName");//绑定客户公司的员工
                ddlEmployee.SelectedValue = entity.所属员工.ToString();
            }




            ddlEmployee.SelectedValue = entity.所属员工.ToString();
            DropDownList1.SelectedValue = entity.主机类型.ToString();
            DropDownList2.SelectedValue = entity.操作系统.ToString();
            DropDownList3.SelectedValue = entity.系统优化软件.ToString();
            DropDownList4.SelectedValue = entity.PDF软件.ToString();
            DropDownList5.SelectedValue = entity.办公软件.ToString();
            DropDownList6.SelectedValue = entity.邮件收发软件.ToString();
            DropDownList7.SelectedValue = entity.聊天软件1.ToString();
            DropDownList8.SelectedValue = entity.聊天软件2.ToString();
            DropDownList9.SelectedValue = entity.视频播放软件1.ToString();
            DropDownList10.SelectedValue = entity.视频播放软件2.ToString();
            DropDownList11.SelectedValue = entity.音乐播放软件.ToString();
            DropDownList12.SelectedValue = entity.WEB浏览软件.ToString();
            DropDownList13.SelectedValue = entity.下载软件.ToString();
            DropDownList14.SelectedValue = entity.系统备份软件.ToString();
            DropDownList15.SelectedValue = entity.压缩软件.ToString();
            DropDownList16.SelectedValue = entity.平面设计软件1.ToString();
            DropDownList17.SelectedValue = entity.平面设计软件2.ToString();
            DropDownList18.SelectedValue = entity.平面设计软件3.ToString();
            DropDownList19.SelectedValue = entity.平面设计软件4.ToString();
            DropDownList20.SelectedValue = entity.三维设计软件1.ToString();
            DropDownList21.SelectedValue = entity.三维设计软件2.ToString();
            DropDownList22.SelectedValue = entity.网页制作软件1.ToString();
            DropDownList23.SelectedValue = entity.网页制作软件2.ToString();
            DropDownList24.SelectedValue = entity.财务软件1.ToString();
            DropDownList25.SelectedValue = entity.财务软件2.ToString();
            DropDownList26.SelectedValue = entity.财务软件3.ToString();
            DropDownList27.SelectedValue = entity.财务软件4.ToString();
            DropDownList28.SelectedValue = entity.杀毒软件.ToString();
            DropDownList29.SelectedValue = entity.安全防护软件.ToString();
            //DropDownList30.SelectedValue = entity.打印机1.ToString();
            //DropDownList31.SelectedValue = entity.打印机2.ToString();
            //DropDownList32.SelectedValue = entity.打印机3.ToString();
            //DropDownList33.SelectedValue = entity.打印机4.ToString();
            this.txtPrint1.Text = entity.打印机1.ToString();
            this.txtPrint2.Text = entity.打印机2.ToString();
            this.txtPrint3.Text = entity.打印机3.ToString();
            this.txtPrint4.Text = entity.打印机4.ToString();
            this.txtScan1.Text = entity.扫描仪1.ToString();
            this.txtScan2.Text = entity.扫描仪2.ToString();
            //DropDownList34.SelectedValue = entity.扫描仪1.ToString();
            //DropDownList35.SelectedValue = entity.扫描仪2.ToString();
            txtRemarks.Text = entity.Remarks;
        }

        private void BindData()
        {
            DropDownListHelper.InitDropList<tbUserEntity>(new tbUserEntity().GetAllByQuery("RoleGroup=" + (int)PubEnums.RoleGroup.客户), ddlCompanyID, "ID", "CompanyName");//绑定公司
            if (SessionHelper.UserRoleGroup == PubEnums.RoleGroup.客户.ToString())
            {
                ddlCompanyID.SelectedValue = SessionHelper.UserCompanyID.ToString();
                ddlCompanyID.Enabled = false;
                DropDownListHelper.InitDropList<tbCustEmployeeInfoEntity>(new tbCustEmployeeInfoEntity().GetAllByQuery("CompanyID=" + ddlCompanyID.SelectedValue), ddlEmployee, "ID", "RealName");//绑定客户公司的员工

            }

            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=1"), this.DropDownList1, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=2"), this.DropDownList2, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=3"), this.DropDownList3, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=4"), this.DropDownList4, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=5"), this.DropDownList5, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=6"), this.DropDownList6, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=7"), this.DropDownList7, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=8"), this.DropDownList8, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=9"), this.DropDownList9, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=10"), this.DropDownList10, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=11"), this.DropDownList11, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=12"), this.DropDownList12, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=13"), this.DropDownList13, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=14"), this.DropDownList14, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=15"), this.DropDownList15, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=16"), this.DropDownList16, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=17"), this.DropDownList17, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=18"), this.DropDownList18, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=19"), this.DropDownList19, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=20"), this.DropDownList20, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=21"), this.DropDownList21, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=22"), this.DropDownList22, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=23"), this.DropDownList23, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=24"), this.DropDownList24, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=25"), this.DropDownList25, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=26"), this.DropDownList26, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=27"), this.DropDownList27, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=28"), this.DropDownList28, "ID", "SoftName");
            DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=29"), this.DropDownList29, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=30"), this.DropDownList30, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=31"), this.DropDownList31, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=32"), this.DropDownList32, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=33"), this.DropDownList33, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=34"), this.DropDownList34, "ID", "SoftName");
            //DropDownListHelper.InitDropList<tb软件清单Entity>(new tb软件清单Entity().GetAllByQuery(" SoftType=35"), this.DropDownList35, "ID", "SoftName");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                tbCustEmpSoftListEntity entity = new tbCustEmpSoftListEntity();
                if (ViewState["Entity"] != null)
                {
                    entity = ViewState["Entity"] as tbCustEmpSoftListEntity;
                }
                else
                {
                    entity.CreateBy = SessionHelper.UserID;
                    entity.CreateDate = DateTime.Now;
                }
                entity.所属公司 = (int.Parse(ddlCompanyID.SelectedValue));
                entity.所属员工 = (int.Parse(ddlEmployee.SelectedValue));

                entity.主机类型 = int.Parse(DropDownList1.SelectedValue);
                entity.操作系统 = int.Parse(DropDownList2.SelectedValue);
                entity.系统优化软件 = int.Parse(DropDownList3.SelectedValue);
                entity.PDF软件 = int.Parse(DropDownList4.SelectedValue);
                entity.办公软件 = int.Parse(DropDownList5.SelectedValue);
                entity.邮件收发软件 = int.Parse(DropDownList6.SelectedValue);
                entity.聊天软件1 = int.Parse(DropDownList7.SelectedValue);
                entity.聊天软件2 = int.Parse(DropDownList8.SelectedValue);
                entity.视频播放软件1 = int.Parse(DropDownList9.SelectedValue);
                entity.视频播放软件2 = int.Parse(DropDownList10.SelectedValue);
                entity.音乐播放软件 = int.Parse(DropDownList11.SelectedValue);
                entity.WEB浏览软件 = int.Parse(DropDownList12.SelectedValue);
                entity.下载软件 = int.Parse(DropDownList13.SelectedValue);
                entity.系统备份软件 = int.Parse(DropDownList14.SelectedValue);
                entity.压缩软件 = int.Parse(DropDownList15.SelectedValue);
                entity.平面设计软件1 = int.Parse(DropDownList16.SelectedValue);
                entity.平面设计软件2 = int.Parse(DropDownList17.SelectedValue);
                entity.平面设计软件3 = int.Parse(DropDownList18.SelectedValue);
                entity.平面设计软件4 = int.Parse(DropDownList19.SelectedValue);
                entity.三维设计软件1 = int.Parse(DropDownList20.SelectedValue);
                entity.三维设计软件2 = int.Parse(DropDownList21.SelectedValue);
                entity.网页制作软件1 = int.Parse(DropDownList22.SelectedValue);
                entity.网页制作软件2 = int.Parse(DropDownList23.SelectedValue);
                entity.财务软件1 = int.Parse(DropDownList24.SelectedValue);
                entity.财务软件2 = int.Parse(DropDownList25.SelectedValue);
                entity.财务软件3 = int.Parse(DropDownList26.SelectedValue);
                entity.财务软件4 = int.Parse(DropDownList27.SelectedValue);
                entity.杀毒软件 = int.Parse(DropDownList28.SelectedValue);
                entity.安全防护软件 = int.Parse(DropDownList29.SelectedValue);
                //entity.打印机1 = int.Parse(DropDownList30.SelectedValue);
                //entity.打印机2 = int.Parse(DropDownList31.SelectedValue);
                //entity.打印机3 = int.Parse(DropDownList32.SelectedValue);
                //entity.打印机4 = int.Parse(DropDownList33.SelectedValue);
                entity.打印机1 = this.txtPrint1.Text.Trim();
                entity.打印机2 = this.txtPrint2.Text.Trim();
                entity.打印机3 = this.txtPrint3.Text.Trim();
                entity.打印机4 = this.txtPrint4.Text.Trim();
                entity.扫描仪1 = this.txtScan1.Text.Trim();
                entity.扫描仪2 = this.txtScan2.Text.Trim();

                entity.Remarks = txtRemarks.Text.Trim();
                entity.SaveOrUpdate(entity);
                ViewState["Entity"] = entity;
                entity.ModifyBy = SessionHelper.UserID;
                entity.ModifyDate = DateTime.Now;
                MessageboxInfo.MessageBox(this, MessageType.SUCCEEDED, "保存成功");
            }
            catch (Exception ex)
            {
                log4netHelper.error(ex);
                MessageboxInfo.MessageBox(this, MessageType.ERROR, "保存失败");
            }
        }



        protected void ddlCompanyID_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCompanyID.SelectedValue != "-1")
            {
                DropDownListHelper.InitDropList<tbCustEmployeeInfoEntity>(new tbCustEmployeeInfoEntity().GetAllByQuery("CompanyID=" + ddlCompanyID.SelectedValue), ddlEmployee, "ID", "RealName");//绑定客户公司的员工
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("UserAssetList.aspx", true);
        }
    }
}
